package com.example.yunJie.digitalSentry.util;

import com.alibaba.fastjson.JSONObject;
import com.example.yunJie.digitalSentry.entity.FaceDownEntity;
import com.example.yunJie.digitalSentry.service.FaceDownService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ConnectionInterface {

    @Autowired
    private static FaceDownService faceDownService;

    public final static String requestUrl ="http://101.89.133.43:5180/deliverySyncPersonToDevice";

    public static String getResponse(){
//        Map<String,Object> map = new HashMap<String, Object>();
//        map.put("devSno","JWJA220511188");
//        map.put("pidList","32111232");
//        map.put("idCardList","3303************19");
//        map.put("personNameList","朱挺");
//        map.put("templateImgUrlList","https://zhutingtest.oss-cn-shanghai.aliyuncs.com/otaSoftware/sfsf/微信图片_20230203164421.png");
//        JSONObject json = new JSONObject(map);
//        String s = UrlConnection.sendPost(requestUrl,json.toJSONString(),null);


        List<FaceDownEntity> all = faceDownService.findAll();
        Map<String,Object> map = new HashMap<String, Object>();
        for (FaceDownEntity faceDownEntity:all){
            map.put("devSno",faceDownEntity.getDevSno());
            map.put("pidList",faceDownEntity.getPidList());
            map.put("idCardList",faceDownEntity.getIdCardList());
            map.put("personNameList",faceDownEntity.getPersonNameList());
            map.put("templateImgUrlList",faceDownEntity.getTemplateImgUrlList());
        }
        JSONObject json = new JSONObject(map);
        String s = UrlConnection.sendPost(requestUrl,json.toJSONString(),null);
        return s;
    }

    public static StringBuilder mapTos(Map<String,String> params) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> e : params.entrySet()) {
            sb.append(e.getKey());
            sb.append("=");
            sb.append(e.getValue());
            sb.append("&");
        }
        return sb;
    }

}
